package org.vectrics.company.dataweb;

import java.util.Iterator;

import javax.servlet.http.HttpServletRequest;

import org.vectrics.company.Company;
import org.vectrics.company.CompanySelectCriteria;
import org.vectrics.dataweb.WebServiceAction;
import org.vectrics.provider.CoreServiceLocator;
import org.vectrics.struts.Request;
import org.vectrics.VectricsException;
import org.apache.log4j.Logger;
import org.w3c.dom.Element;


public class FindCompanyIdsAction extends WebServiceAction {
	static private transient Logger log = Logger.getLogger(FindCompanyIdsAction.class);
	static private String COMMAND_NOT_FOUND = "Command not found or not given: ";	
	
	public FindCompanyIdsAction() {
		super();
	}

	public void getData(Request request, String command, Element requestData, 
			Element dataElement) {
		
		Element searchElement = null;
		String userId = null;
		log.debug("getData() - put user details in document");
		Element companyListElement = dataElement.getOwnerDocument().createElement("companyList");
		dataElement.appendChild(companyListElement);
		CompanySelectCriteria criteria = new CompanySelectCriteria();
		Iterator iter = CoreServiceLocator.getCompanyService().findCompanies(criteria, 0, 100).iterator();
		while (iter.hasNext()) {
			Company company = (Company)iter.next();
			Element companyElement = companyListElement.getOwnerDocument().createElement("company");
			companyListElement.appendChild(companyElement);
			companyElement.setAttribute("id", company.getId().toString());
		}
	}


	
}

